<?php
namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Cookie;


class Tourism extends Controller
{
    public function tourism()
    { if(Cookie::has("username")){
        $name=Cookie::get("username")." <a href='".url('Index/cancel')."'>注销</a>";
    }else{
        $name=' <a href="'.url('Index/login').'">登录&注册</a>';
    }
//        旅游主页

//        周边
        $c = Db::name('scenic_spot')->limit(7,14)->select();
        $aa = array();
        for($i=0;$i<count($c);$i++){
            $aa[$i]['img'] = explode("/",$c[$i]["img"]);
        }
        $this->assign('c', $c);
        $this->assign('aaa', $aa);
//        国内c
        $a=Db::name('scenic_spot')->where('Agritainment',0)->where("class","0")->paginate(4);
        $_a = array();
        for($i=0;$i<count($a);$i++){
            $_a[$i]['img'] = explode("/",$a[$i]["img"]);
        }
        $this->assign('a', $a);
        $this->assign('as', $_a);
//        国外
        $b = Db::name('scenic_spot')->where("class","1")->paginate();
        $_b = array();
        for($i=0;$i<count($b);$i++){
            $_b[$i]['img'] = explode("/",$b[$i]["img"]);
        }
        $this->assign('b', $b);
        $this->assign('bs', $_b);
        return view("Tourism/tourism",["username"=>$name]);
    }
    public function _app(){
//        旅游添加
        return view("tourism/tourism-app");
    }
    public function tourism_zhou(){
//        周边旅游
    $list = Db::name('scenic_spot')->paginate();
    $this->assign('list', $list);
    return $this->fetch('tourism_list');
}
    public function tourism_guo(){
        //国内旅游
        $list = Db::name('scenic_spot')->where("class","0")->paginate();
        $this->assign('list', $list);
        return $this->fetch('tourism_list_g');
    }
    public function tourism_wai(){
        //境外旅游
    $list = Db::name('scenic_spot')->where("class","1")->paginate();
    $this->assign('list', $list);
    return $this->fetch('tourism_list_w');
}

    //导游
    public function tourism_guide(){
        if(Cookie::has("username")){
            $name=Cookie::get("username")." <a href='".url('Index/cancel')."'>注销</a>";
        }else{
            $name=' <a href="'.url('Index/login').'">登录&注册</a>';
        }

        $list = Db::name('guide')->paginate();
        $this->assign('list', $list);
        return view("Tourism/guide",["username"=>$name]);

    }
//农家乐
    public function agritainment(){
        if(Cookie::has("username")){
            $name=Cookie::get("username")." <a href='".url('Index/cancel')."'>注销</a>";
        }else{
            $name=' <a href="'.url('Index/login').'">登录&注册</a>';
        }
        $data=Db::table("scenic_spot")->where('Agritainment',1)->paginate(6);
        $ccc= array();
        for($i=0;$i<count($data);$i++){
            $ccc[$i]['img'] = explode("/",$data[$i]["img"]);
        }
        $this->assign('data', $data);
        $this->assign('ccc', $ccc);
        return view("Tourism/agritainment",["username"=>$name]);

    }



    //路线
    public function tourism_route(){
        if(Cookie::has("username")){
            $name=Cookie::get("username")." <a href='".url('Index/cancel')."'>注销</a>";
        }else{
            $name=' <a href="'.url('Index/login').'">登录&注册</a>';
        }
        $list = Db::name('route')->paginate();
        $cc = array();
        for($i=0;$i<count($list);$i++){
            $cc[$i]['img'] = explode("/",$list[$i]["img"]);
        }
        $this->assign('li', $cc);
        $this->assign('list', $list);
        return view("Tourism/route",["username"=>$name]);
    }
    //景点预定
    public function tourism_order(){
        if(Cookie::has("username")){
            $name=Cookie::get("username")." <a href='".url('Index/cancel')."'>注销</a>";
        }else{
            $name=' <a href="'.url('Index/login').'">登录&注册</a>';
        }
        $get= $_GET['id'];
        $list = Db::name('scenic_spot')->where('id',$get)->paginate();
        $cc = array();
        for($i=0;$i<count($list);$i++){
            $cc[$i]['img'] = explode("/",$list[$i]["img"]);
        }
        $this->assign('li', $cc);
        $this->assign('list', $list);
        return view("Tourism/tourism_order",["username"=>$name]);
    }
//    路线预定
    public function tourism_order_1(){
        if(Cookie::has("username")){
            $name=Cookie::get("username")." <a href='".url('Index/cancel')."'>注销</a>";
        }else{
            $name=' <a href="'.url('Index/login').'">登录&注册</a>';
        }
        $get= $_GET['id'];
        $list = Db::name('route')->where('id',$get)->paginate();
        $cc = array();
        for($i=0;$i<count($list);$i++){
            $cc[$i]['img'] = explode("/",$list[$i]["img"]);
        }
        $this->assign('li', $cc);
        $this->assign('list', $list);
        return view("Tourism/tourism_order_r",["username"=>$name]);
    }

//    订单页面

    public function order()
    {
        $data = $_POST;
        $a = $_POST['price'];
        $data['price_c'] = $a * 0.5;
        $data['order_sn'] = time();
        $name = Cookie::get("username");
        $data['name'] = $name;
        if ($name == "") {
            $this->success("您还没登录，不能进行以下操作", "Index/login", "", 1);
        } else {
             Db::table('tourism')->insert($data);
                return true;
        }
    }
//    订单页面提交跳转
    public function order_1(){
        if(Cookie::has("username")){
            $name=Cookie::get("username")." <a href='".url('Index/cancel')."'>注销</a>";
        }else{
            $name=' <a href="'.url('Index/login').'">登录&注册</a>';
        }
        $list = Db::name('tourism')->order("id desc")->find();
        return view("Tourism/order",["username"=>$name,"list"=>$list]);
    }
    public function order_2(){
        return view("Index/login");

    }
    public function order_3(){
        return $this->tourism();

    }
//    支付页面跳转
    public function order_t()
    {   $data = $_POST;
        $a=$_POST['route_id'];
        if(Db::table('tourism')->where('id',$a)->update($data))
        {
            return true;
        }else{
            return false;
        }
    }

}

